<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

<button type="button" onclick="lightbulb()">灯泡开关</button>
<img id="myimage" onclick="changeImage()" src="https://www.runoob.com/images/pic_bulbon.gif" width="100" height="180"  alt="">
<script>
    function lightbulb () {
        let element  =  document.getElementById('myimage')
      if (element.src.match('pic_bulbon')){
          element.src = 'https://www.runoob.com/images/pic_bulboff.gif'
      }      
    else(element.src = 'https://www.runoob.com/images/pic_bulbon.gif')
    
    }
</script>  
  
</body>
</html>